package handler

import (
	"fmt"
	"gozero-microservices/gateway-api/internal/tools"
	"net/http"
)

/*
 +----------------------------------------------------------------------
 + Title        : IndexHandler
 + Author       : huwl
 + Version      : 1.0.0
 + Initial-Time : 2025-08-08
 + Last-time    : 这个文件最后修改的时间 + 修改人的名称
 + Desc         : 首页处理器
 +----------------------------------------------------------------------
*/

type IndexHandler struct {
	BaseHandler
}

/**
 * 首页
 *
 * @author huwl
 */
func (control *IndexHandler) Index(w http.ResponseWriter, r *http.Request) {
	control.SvcCtx.Logger.Info("xxxx")
	control.BaseSuccess(r, w, control.WithMessage("欢迎使用 gozero v1.5.0 单体框架！！！"))
}

/**
 * 案例
 *
 * @author huwl
 */
func (control *IndexHandler) Demo(w http.ResponseWriter, r *http.Request) {
	control.BaseSuccess(r, w, control.WithMessage("index demo"))
}

/**
 * mongo案例
 *
 * @author huwl
 */
func (control *IndexHandler) MongoDemo(w http.ResponseWriter, r *http.Request) {
	mongoInstance, err := tools.NewMongoInstance(control.SvcCtx)
	if err != nil {
		control.BaseError(r, w, control.WithMessage(err.Error()))
		return
	}

	fmt.Println("mongoInstance =", mongoInstance)

	control.BaseSuccess(r, w, control.WithMessage("mongo demo"))
}
